package buildcode.language;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public abstract class Type<T extends Field> {
    private String remark;
    private String typeName;
    private String packagePath;
    private List<Type> importTypes = new ArrayList<Type>();
    private List<T> fields = new ArrayList<T>();
    private Map<String, Object> extraData = new HashMap<String, Object>();

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String name) {
        this.typeName = name;
    }

    public Type(String name, String packagePath) {
        super();
        this.typeName = name;
        this.packagePath = packagePath;
    }

    public String getPackagePath() {
        return packagePath;
    }

    public void setPackagePath(String packagePath) {
        this.packagePath = packagePath;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public List<Type> getImportTypes() {
        return importTypes;
    }

    public void setImportTypes(List<Type> importTypes) {
        this.importTypes = importTypes;
    }

    public Map<String, Object> getExtraData() {
        return extraData;
    }

    public void setExtraData(Map<String, Object> extraData) {
        this.extraData = extraData;
    }

    public abstract String getClassFullPath();

    @Override
    public int hashCode() {
        return Objects.hash(packagePath, typeName);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Type other = (Type) obj;
        return Objects.equals(packagePath, other.packagePath) && Objects.equals(typeName, other.typeName);
    }

    public List<T> getFields() {
        return fields;
    }

    public void setFields(List<T> fields) {
        this.fields = fields;
    }

    public void addField(T field) {
        this.fields.add(field);
    }

}
